using System;
using System.Collections.Generic;
using UnityEngine;

public class CameraBehavioursDB : ScriptableObject
{
	public enum CameraGroupType
	{
		Group0 = 0,
		Group1 = 1,
		Group2 = 2,
		Group3 = 3,
		Group4 = 4,
		Group5 = 5,
		Group6 = 6,
		Group7 = 7,
		Group8 = 8,
		Group9 = 9,
		Group10 = 10,
		Group11 = 11,
		Group12 = 12,
		Group13 = 13,
		Group14 = 14,
		Group15 = 15,
		Group16 = 16,
		DefaultGroup = 17
	}

	protected class CameraGroupStatus
	{
		public CameraGroupType type;

		public int usedTimes;
	}

	private static CameraBehavioursDB instance_;

	public List<TTCameraBehaviourPrepareForAction> prepareBehaviours = new List<TTCameraBehaviourPrepareForAction>();

	public List<TTCameraBehaviourObserveAction> observeBehaviours = new List<TTCameraBehaviourObserveAction>();

	public List<TTCameraBehaviourFollowPosition> followBehaviours = new List<TTCameraBehaviourFollowPosition>();

	public List<TTCameraBehaviourFlyAroundObject> flyAroundObjectBehaviours = new List<TTCameraBehaviourFlyAroundObject>();

	public List<TTCameraBehaviourPlayCamera> playCameras = new List<TTCameraBehaviourPlayCamera>();

	public List<TTCameraBehaviourServeCamera> serveCameras = new List<TTCameraBehaviourServeCamera>();

	public List<TTCameraBehaviourLookAtBall> lookAtCameras = new List<TTCameraBehaviourLookAtBall>();

	public List<TTCameraBehaviourZoomToPlayer> zoomCameras = new List<TTCameraBehaviourZoomToPlayer>();

	public List<TTCameraBehaviourRacketPlayer> racketCameras = new List<TTCameraBehaviourRacketPlayer>();

	public List<TTCameraBehaviourStaticCamera> staticCameras = new List<TTCameraBehaviourStaticCamera>();

	protected List<TTCameraBehaviour> allBehaviours;

	public static CameraBehavioursDB instance
	{
		get
		{
			if (instance_ == null)
			{
				instance_ = Resources.Load("CameraBehavioursDB", typeof(CameraBehavioursDB)) as CameraBehavioursDB;
			}
			return instance_;
		}
	}

	public List<TTCameraBehaviour> GetAllBehaviours()
	{
		if (allBehaviours != null)
		{
			return allBehaviours;
		}
		allBehaviours = new List<TTCameraBehaviour>();
		foreach (TTCameraBehaviourStaticCamera staticCamera in staticCameras)
		{
			allBehaviours.Add(staticCamera);
		}
		foreach (TTCameraBehaviourPrepareForAction prepareBehaviour in prepareBehaviours)
		{
			allBehaviours.Add(prepareBehaviour);
		}
		foreach (TTCameraBehaviourObserveAction observeBehaviour in observeBehaviours)
		{
			allBehaviours.Add(observeBehaviour);
		}
		foreach (TTCameraBehaviourFollowPosition followBehaviour in followBehaviours)
		{
			allBehaviours.Add(followBehaviour);
		}
		foreach (TTCameraBehaviourFlyAroundObject flyAroundObjectBehaviour in flyAroundObjectBehaviours)
		{
			allBehaviours.Add(flyAroundObjectBehaviour);
		}
		foreach (TTCameraBehaviourPlayCamera playCamera in playCameras)
		{
			allBehaviours.Add(playCamera);
		}
		foreach (TTCameraBehaviourServeCamera serveCamera in serveCameras)
		{
			allBehaviours.Add(serveCamera);
		}
		foreach (TTCameraBehaviourLookAtBall lookAtCamera in lookAtCameras)
		{
			allBehaviours.Add(lookAtCamera);
		}
		foreach (TTCameraBehaviourZoomToPlayer zoomCamera in zoomCameras)
		{
			allBehaviours.Add(zoomCamera);
		}
		foreach (TTCameraBehaviourRacketPlayer racketCamera in racketCameras)
		{
			allBehaviours.Add(racketCamera);
		}
		return allBehaviours;
	}

	public List<CameraGroupType> UsedCameraGroupTypes()
	{
		List<TTCameraBehaviour> list = GetAllBehaviours();
		List<CameraGroupStatus> list2 = new List<CameraGroupStatus>();
		foreach (CameraGroupType value in Enum.GetValues(typeof(CameraGroupType)))
		{
			list2.Add(new CameraGroupStatus
			{
				type = value
			});
		}
		foreach (TTCameraBehaviour allBehaviour in GetAllBehaviours())
		{
			foreach (CameraGroupType supportedGroup in allBehaviour.supportedGroups)
			{
				list2[(int)supportedGroup].usedTimes++;
			}
		}
		List<CameraGroupType> list3 = new List<CameraGroupType>();
		foreach (CameraGroupStatus item in list2)
		{
			if (item.usedTimes > 0)
			{
				list3.Add(item.type);
			}
		}
		return list3;
	}

	public TTCameraBehaviour GetCameraBehaviour(CameraGroupType groupType, TTCameraBehaviour.GameplayIntervalType gameIntervalType)
	{
		List<TTCameraBehaviour> list = GetAllBehaviours();
		foreach (TTCameraBehaviour item in list)
		{
			if (item.IsGameIntervalSupported(gameIntervalType) && item.IsGroupSupported(groupType))
			{
				return item;
			}
		}
		foreach (TTCameraBehaviour item2 in list)
		{
			if (item2.IsGameIntervalSupported(gameIntervalType))
			{
				return item2;
			}
		}
		return null;
	}
}
